package com.tencent.welink.api.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tencent.welink.api.base.WelinkOpenApi;
import com.tencent.welink.config.BussinessConfig;
import com.tencent.welink.util.CrontabUtil;
import com.tencent.welink.api.OpenApiTokenChange;
import org.apache.http.entity.ContentType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Map;

/**
 * @Description: 调用第三方服务
 * @Author: limye
 * @CreateDate: 2020-6-8
 * @Version: V1.0
 */
public class CallThirdService extends WelinkOpenApi {

    private static final Logger log = LogManager.getLogger(CallThirdService.class);

    public CallThirdService(){
        super("/common/logic/call",false,ContentType.APPLICATION_JSON);
    }


    @Override
    public void displayResult(String result) {
        log.info("do nothing here");
    }


    public static void main(String[] args) {
        new BussinessConfig();
        CrontabUtil.addTaskInRate(new OpenApiTokenChange(), BussinessConfig.loginDurationMinutes,true);

        //实例化对象
        CallThirdService instance = new CallThirdService();

        //添加参数
        Map<String,Object> map = instance.getExtendsPara();
        map.put("service_id",100068);
        map.put("api_id",14);
        map.put("project_id",172);

        JSONArray jsonArr = new JSONArray();
        JSONObject paramJson1 = new JSONObject();
        paramJson1.put("name","action");
        paramJson1.put("value","detect");
        jsonArr.add(paramJson1);
        JSONObject paramJson2 = new JSONObject();
        String imgStr = "base64teststr";
        paramJson2.put("name","picdata");
        paramJson2.put("value",imgStr);
        jsonArr.add(paramJson2);
        instance.getBodyPara().put("params",jsonArr);


        //执行HTTP请求及展示结果
        instance.DoHttp();
        CrontabUtil.shutdown();
    }
}